package com.hushao.aimi.repository;

import com.hushao.aimi.entity.AimiCart;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface CartRepository extends JpaRepository<AimiCart,String> {
    @Query(value = "SELECT a.id as cart_id,d.id as product_id,d.name as productName, d.subtitle as productTitle," +
            "c.id as product_spec_id,c.name,c.image,c.price,a.number " +
            "FROM aimi_cart a JOIN aimi_user b ON a.user_id=b.id " +
            "join aimi_product_spec c ON a.product_spec_id=c.id " +
            "JOIN aimi_product d on c.product_id=d.id WHERE b.username= :username" ,nativeQuery = true)
    List<Object> getProductSpecsByUsername(@Param("username") String username);

    /**
     * 根据用户和商品规格id查询
     * @param userId
     * @param ProductSpecId
     * @return
     */
    AimiCart findByUserIdAndAndProductSpecId(String userId,String ProductSpecId);
}
